<%@ page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@page import="com.ufida.ebscg.comm.session.UserBean;"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>招商银行供应商门户-采购创造价值-供应商自助_产品价格维护</title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/style_add.css" rel="stylesheet" type="text/css" />
<link href="css/selfcss.css" rel="stylesheet" type="text/css" /></head>
<script language="JavaScript" type="text/javascript" src="../calendar/WdatePicker.js"></script>
<script language="JavaScript" type="text/javascript" src="../javascript/caltimer.js"></script>
<script language="JavaScript" type="text/javascript" src="../javascript/ajaxdeal.js"></script>
<body style="width:610px">
<div id="main">
<!--左侧内容开始-->

<!--右侧内容开始-->
<input type="hidden" id="cstate" value="${cstate}" />


<div id="showunit">
      
</div>

<div style="width:650px;overflow:auto;margin-left:20px">

<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td><span class="f-12-4f4f4f">框架协议名称:</span><strong><span class="f-14-e57c00">${ct_title }</span></strong></td>
    </tr>
    <tr>
      <td align="right">
	      	<form action="constrat.do" name="downprint" method="post">
	      	 
				<input type="submit" value="模版下载" />
				<input type="hidden" name = "type" value = "4"/>
				 
				<input type="hidden" name="constratpk" value="${constratpk }"/>
				<!--
				 <input type="button" value="导    入"  onclick="importPrice()" <logic:notEqual value="8" name="cstate"> disabled</logic:notEqual>  />
				 -->
	      		<input type="button" value="增    行" onclick="addRow()"  <logic:notEqual value="8" name="cstate"> disabled</logic:notEqual> />
	      		<input type="button" value="删    行" onclick="deleteRow()" <logic:notEqual value="8" name="cstate"> disabled</logic:notEqual> />
				
			</form>
	     
      </tr>
</table>
</div>

<form action="constrat.do" name="constratform" method="post">


<input type="hidden" name = "type" value = "3"/>
<input type="hidden" name="price_type" value="${type }"/>
    
<div style="width:680px;overflow:auto;height:300px;margin-left:20px">
  <input type="hidden" name="constratpk" value="${constratpk }" id="constratpk"/>
    <table width="1500px" border="0" cellpadding="0" cellspacing="0" id="pricetable" >
        <tr>
           <td  height="28" style = "width:100px" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">产品编码</span></td>
          <td  height="28" style = "width:150px" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">产品/服务名称</span></td>
          <td  height="28"  style = "width:150px" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">型号</span></td>
          <td  height="28" style = "width:200px" align="center" background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">详细描述（规格/技术参数）</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">数量</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">单位</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">列表单价</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">正折扣率(%)</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">折扣后单价</span></td>
           <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">折扣后总价</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">生效日期</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">失效日期</span></td>
          <td  height="28" align="center"  background="../images/th_bgc.jpg"><span class="f-12-b-ffffff">备注</span></td>
        </tr>
    
      <logic:iterate id="prod" name="prods">
       <tr>
       
       <logic:equal value="true" name="prod" property = "is_modify_price_list">
       		<input type="hidden" value="${prod.pk_ht_prod_price_repo }" name="pk_ht_prod_price_repo"/>
       </logic:equal>
       	  <td height="35" style = "width:100px" align="center">${prod.prod_no }</td>
          <td height="35" style = "width:150px" align="center">${prod.prod_name }
          <input type="hidden" name="prod_name" value="${prod.prod_name}" />
          </td>
          <td align="center" style = "width:150px" >${prod.prod_specs }
          <input type="hidden" name="prod_specs" value="${prod.prod_specs}"/>
          </td>
          <td align="center" style = "width:200px">${prod.prod_config_desc }
          <input type="hidden" name="prod_config_desc" value="${prod.prod_config_desc}"/>
          </td>
           <td align="center"><input type='text' name='prod_num' value='${prod.prod_num}' size='3'
	            <logic:equal value="false" name="prod" property = "is_modify_price_list">
	       		disabled
	       		</logic:equal>
       	 	/>
       	 </td>
          <td align="center">${prod.prod_unit}
           <input type="hidden" name="prod_unit" value="${prod.prod_unit}"/>
          </td>
        
       	  <td align="center">
       	  
       	  <input name="cate_unit_price" type="text" value="${prod.cate_unit_price }" size="6"
       	  id="cate_unit_price${prod.index}" 
       	  <logic:equal value="false" name="prod" property = "is_modify_price_list">
       		disabled
       	</logic:equal>
       	  />
       	  
       	  </td>
          <td align="center">
          
          <input name="positive_discount" type="text" value="${prod.positive_discount }" 
          size="6" id="positive_discount${prod.index}" 
          <logic:equal value="false" name="prod" property = "is_modify_price_list">
       		disabled
       	</logic:equal>
          />
          </td>
         
          
          
          <td align="center">
          
          <input name="discounted_unit_price" type="text" value="${prod.discounted_unit_price }" size="6" 
          
          id="discounted_unit_price${prod.index}"
          
          <logic:equal value="false" name="prod" property = "is_modify_price_list">
       		disabled
       	</logic:equal>
       	
          />
          
          </td>
          
          <td align="center">
          
          <input name="discounted_amount" type="text" value="${prod.discounted_amount }" size="6" 
          
          id="discounted_amount${prod.index}"
          
          <logic:equal value="false" name="prod" property = "is_modify_price_list">
       		disabled
       	</logic:equal>
       	
          />
          
          </td>
        
        
          <td align="center"><input name="effective_date" type="text" value="${prod.effective_date }" size="7" 
          <logic:equal value="true" name="prod" property = "is_modify_price_list">
          onclick="WdatePicker()" 
          </logic:equal>
          readonly/></td>
          <td align = "center"> <input name="ineffective_date" type="text" value="${prod.ineffective_date }" size="7" 
          <logic:equal value="true" name="prod" property = "is_modify_price_list">
          onclick="WdatePicker()" 
          </logic:equal> readonly/></td>
           <td align = "center"> <TEXTAREA  name="memo" cols='10' rows='3'  <logic:equal value="false" name="prod" property = "is_modify_price_list">
       		disabled
       	</logic:equal>>${prod.memo}</TEXTAREA></td>
    
        </tr>
        <tr>
          <td colspan="13" height="1" bgcolor="#7f98ae"></td>
        </tr>
       </logic:iterate>
      </table>
  
 </div> 
 <div style="width:680px;overflow:auto;height:150px;margin-left:20px">
 <span><strong class="f-13-b-2a6ca7">框架协议附件</strong></span>
 <table width="680" border="0" cellpadding="0" cellspacing="0">
           <tr>
             <td  height="28" align="center"  background="../images/th_bgc.jpg" width="100"><span class="f-12-b-ffffff">序号</span></td>
         	 <td  height="28" align="center"  background="../images/th_bgc.jpg" width="500"><span class="f-12-b-ffffff">附件名称</span></td>
         	 <td  height="28" align="center"  background="../images/th_bgc.jpg" width="80"><span class="f-12-b-ffffff">下载</span></td>
          </tr>
          
          <logic:iterate id="att" name="atts">
          
          	<tr>
          	    <td  height="28" align="center" width="100" >${att.zdy2 }</td>
          		<td  height="28" align="center" width="500" >${att.filename }</td>
          		<td  height="28" align="center" width="80" ><a href="/portal/self/constrat.do?type=6&pk_da_att=${att.pk_da_att}" />下载</a></td>
          	</tr>
          	<tr>
         		<td colspan="2" height="1" bgcolor="#7f98ae"></td>
        	</tr>
          
          </logic:iterate>
          
</table>

<br/>

<div style="width:100%;" align="center">
<img src="../images/botton_submit.jpg" width="60" height="20" border="0" onclick="submitValue()" style="cursor:hand"/>
</div>

</form>


<script language="javascript">

var message = "${message}";
var deleteRowIndex = -1;

var newAddRowIndex = 0;
if(message != ""){
	parent.showHideFun();
	parent.changeShowMessage(message,'yes','ok',null,true,toUrlRed);
}

function submitValue()
{
	if(isEditAndSubmit()){

		//对新增加的数据进行验证
		if(!submitValide()){
			return;
		}
		
		parent.showHideFun();
		parent.changeShowMessage("数据处理中,请等候.....");
		document.constratform.submit();
	}else{
		parent.showHideFun();
		parent.changeShowMessage("数据在审批中,无法对数据进行修正!",'yes','ok');
	}
}

function submitValide(){

	
	
	
	//单位getElementsByName
	var cate_unit_price  = document.getElementsByName("cate_unit_price");

	var positive_discount = document.getElementsByName("positive_discount");

	var discounted_unit_price = document.getElementsByName("discounted_unit_price");
	var discounted_amount = document.getElementsByName("discounted_amount");
	
	var prod_num =  document.getElementsByName("prod_num");

	var effective_date = document.getElementsByName("effective_date");

	var ineffective_date = document.getElementsByName("ineffective_date");

	
	if(cate_unit_price != null && cate_unit_price.length>0){
		for(var index=0; index<cate_unit_price.length; index++){
			
			var reg = /(^\d{1,12}$)|(^\d{1,12}\.\d{1,3}$)/

			/*
			if(!reg.test(prod_num[index].value)){
				prod_num[index].focus();
				showMSG("请输入正确的数量!");
				return false;
			}
			*/
			
				
			
			if(!reg.test(cate_unit_price[index].value)){
				//设置获取焦点
				cate_unit_price[index].focus();
				showMSG("请输入正确的列表单价!");
				return false;
			}

			if(!reg.test(positive_discount[index].value)){
				//设置获取焦点
				newpositive_discount[index].focus();
				showMSG("请输入正确的正扣折扣率!");
				return false;
			}

			if(!reg.test(discounted_unit_price[index].value)){
				//设置获取焦点
				discounted_unit_price[index].focus();
				showMSG("请输入正确的折扣后单价!");
				return false;
			}

			if(!reg.test(discounted_amount[index].value)){
				//设置获取焦点
				discounted_amount[index].focus();
				showMSG("请输入正确的折扣后总价!");
				return false;
			}


			if(effective_date != null && effective_date.length > 0){

				if(effective_date[index].value == ""){
					//设置获取焦点
					effective_date[index].focus();
					showMSG("请选择生效日期!");
					return false;
				}

				if(ineffective_date[index].value == ""){
					//设置获取焦点
					ineffective_date[index].focus();
					showMSG("请选择生效日期!");
					return false;
				}

				if(effective_date[index].value >= ineffective_date[index].value){
					//设置获取焦点
					effective_date[index].focus();
					showMSG("生效日期不能大于失效日期!");
					return false;
				}


				
			}
				
		}

	}

	//对新增数据的验证
	//产品或服务名称
	var newprod_names  = document.getElementsByName("newprod_name");
	//单位getElementsByName
	var tprod_unit  = document.getElementsByName("tprod_unit");
	var newcate_unit_price  = document.getElementsByName("newcate_unit_price");

	var newpositive_discount = document.getElementsByName("newpositive_discount");

	var newdiscounted_unit_price = document.getElementsByName("newdiscounted_unit_price");
	var newdiscounted_amount = document.getElementsByName("newdiscounted_amount");
	
	var newprod_num =  document.getElementsByName("newprod_num");

	var neweffective_date = document.getElementsByName("neweffective_date");

	var newineffective_date = document.getElementsByName("newineffective_date");

	var newprod_config_desc = document.getElementsByName("newprod_config_desc");

	var newprod_specs = document.getElementsByName("newprod_specs");


	if(tprod_unit != null && tprod_unit.length > 0){

			for(var index=0; index<tprod_unit.length; index++){

				var newprod_name = newprod_names[index];

				/*
				if(newprod_name.value == ""){
					//设置获取焦点
					newprod_name.focus();
					showMSG("请输入产品名称!");
					return false;
				}
				*/

				if(newprod_specs[index].value == ""){
					//设置获取焦点
					newprod_specs[index].focus();
					showMSG("请输入型号!");
					return false;
				}

				
				if(tprod_unit[index].value == ""){
					//设置获取焦点
					tprod_unit[index].focus();
					showMSG("请选择单位!");
					return false;
				}

				var reg = /(^\d{1,12}$)|(^\d{1,12}\.\d{1,3}$)/

				
				if(!reg.test(newprod_num[index].value)){
					newprod_num[index].focus();
					showMSG("请输入正确的数量!");
					return false;
				}
				
					
				
				if(!reg.test(newcate_unit_price[index].value)){
					//设置获取焦点
					newcate_unit_price[index].focus();
					showMSG("请输入正确的列表单价!");
					return false;
				}

				if(!reg.test(newpositive_discount[index].value)){
					//设置获取焦点
					newpositive_discount[index].focus();
					showMSG("请输入正确的正扣折扣率!");
					return false;
				}

				if(!reg.test(newdiscounted_unit_price[index].value)){
					//设置获取焦点
					newdiscounted_unit_price[index].focus();
					showMSG("请输入正确的折扣后单价!");
					return false;
				}

				if(!reg.test(newdiscounted_amount[index].value)){
					//设置获取焦点
					newdiscounted_amount[index].focus();
					showMSG("请输入正确的折扣后总价!");
					return false;
				}


				if(neweffective_date != null && neweffective_date.length > 0){

					if(neweffective_date[index].value == ""){
						//设置获取焦点
						neweffective_date[index].focus();
						showMSG("请选择生效日期!");
						return false;
					}

					if(newineffective_date[index].value == ""){
						//设置获取焦点
						newineffective_date[index].focus();
						showMSG("请选择生效日期!");
						return false;
					}


					if(neweffective_date[index].value >= newineffective_date[index].value){
						//设置获取焦点
						neweffective_date[index].focus();
						showMSG("生效日期不能大于失效日期!");
						return false;
					}
				}
					
			}
	}

	return true;
}


function showMSG(msg){
	parent.showHideFun();
	parent.changeShowMessage(msg,'yes','ok');
}


function cancelValue()
{
	document.constratform.reset();
}

function hideHideFun(){
    var showtopdiv = document.getElementById("showtopdiv");
    showtopdiv.style.display = "none";
}

function calPriceAndTotal(index,isnew)
{

	//目录单价
	var priceobj = document.all("cate_unit_price"+index);
	//正折扣率
	var positive_discount = document.all("positive_discount"+index);
	//折扣后单价
	var discounted_unit_price = document.all("discounted_unit_price"+index);


	if(isnew){

		priceobj = document.all("newcate_unit_price"+index);
		//正折扣率
		positive_discount = document.all("newpositive_discount"+index);
		//折扣后单价
		discounted_unit_price = document.all("newdiscounted_unit_price"+index);
	}

	if(priceobj != null && positive_discount != null)
	{
		var price = priceobj.value;
		var discount = positive_discount.value;
		var reg = /(^\d{1,8}$)|(^\d{1,8}\.\d{1,3}$)/;
		
		if(price != '' && discount != '')
		{
			if(!reg.test(price))
			{
				priceobj.value = '';
				return;
			}
			if(!reg.test(discount))
			{
				positive_discount.value = '';
				return;
			}
			
			var unitprice = parseFloat(price)*parseFloat(discount)/100;
			if(typeof(discounted_unit_price) == 'object')
			{
				var temp = new String(unitprice);
				
				
				if(!isNaN(temp))
				{
					if(temp.lastIndexOf(".") != -1)
					{
						discounted_unit_price.value = temp.substring(0,temp.lastIndexOf(".")+3);
					}else
					{
						discounted_unit_price.value  = temp;
					}
				}
			}
		}
	}
}

//增行
function addRow(){


	//获取价格信息列表对象
	var priceTable = document.getElementById("pricetable");

	
	var tr = priceTable.insertRow();

	tr.onclick = function(){

		if(deleteRowIndex != -1){
			priceTable.rows[deleteRowIndex].bgColor = "white";
		}

		this.bgColor  = "#2a6ca7";

		var index = -1;

		for(var pos=0; pos<priceTable.rows.length; pos++){

			if(this == priceTable.rows[pos]){
				index = pos;
				break;
			}
		}
		//设置应被删除的行数
		deleteRowIndex = index;
	}

	//产品编码
	var td = tr.insertCell();
	setTdMsg(td,"&nbsp;");
	
	//产品名称
	var td = tr.insertCell();
	/*
	setTdMsg(td,"<input type='text' name='newprod_name'  />");
	*/
	setTdMsg(td,"&nbsp;");
	//规格
	/*td = tr.insertCell(); 
	setTdMsg(td,"<input type='text' name='newprod_specs' />");
	
	td = tr.insertCell(); 
	setTdMsg(td,"<input type='text' name='newprod_config_desc' />");
	*/
	
	td = tr.insertCell(); 
	setTdMsg(td,"<TEXTAREA  name='newprod_specs' cols='10' rows='5'></TEXTAREA>");
	
	td = tr.insertCell(); 
	setTdMsg(td,"<TEXTAREA  name='newprod_config_desc' cols='10' rows='5'></TEXTAREA>");
	td = tr.insertCell(); 
	setTdMsg(td,"<input name='newprod_num' type='text' size='3'/> ");
	
	td = tr.insertCell(); 
	setTdMsg(td,"<input type='text' name='tprod_unit' onclick='onshowDivUnit(this)' size='4' readonly/> <input type='hidden' name='newprodunit' />");

	td = tr.insertCell(); 

	/*
	setTdMsg(td,"<input type='text' name='newcate_unit_price' size='6' id='newcate_unit_price"+newAddRowIndex
			+"' onchange=calPriceAndTotal('"+newAddRowIndex+"',true) />");
			*/


	setTdMsg(td,"<input type='text' name='newcate_unit_price' size='6' id='newcate_unit_price"+newAddRowIndex
			+"'  />");
	
	td = tr.insertCell(); 

	/*
	setTdMsg(td,"<input type='text' name='newpositive_discount' size='6' id='newpositive_discount"+newAddRowIndex
			+"' value='100' onchange=calPriceAndTotal('"+newAddRowIndex+"',true) />");
			*/
			setTdMsg(td,"<input type='text' name='newpositive_discount' size='6' id='newpositive_discount"+newAddRowIndex
					+"' value='100' />");
			
	td = tr.insertCell(); 

	/*
	setTdMsg(td,"<input type='text' name='newdiscounted_unit_price' size='6' id='newdiscounted_unit_price"+newAddRowIndex
			+"' onchange=calPriceAndTotal('"+newAddRowIndex+"',true) />");*/
			setTdMsg(td,"<input type='text' name='newdiscounted_unit_price' size='6' id='newdiscounted_unit_price"+newAddRowIndex
					+"' />");
			td = tr.insertCell(); 
			setTdMsg(td,"<input type='text' name='newdiscounted_amount' size='6' id='newdiscounted_unit_price"+newAddRowIndex
					+"' />");
	
	td = tr.insertCell(); 
	setTdMsg(td,"<input name='neweffective_date' type='text' size='7' onclick='WdatePicker()' readOnly/> ");

	
	td = tr.insertCell(); 
	setTdMsg(td,"<input name='newineffective_date' type='text' size='7' onclick='WdatePicker()' readOnly/> ");

	td = tr.insertCell(); 
	setTdMsg(td,"<TEXTAREA  name='newmemo' cols='10' rows='5'></TEXTAREA> ");
	

 	newAddRowIndex++;
 	

}


function deleteRow(){

	
	var priceTable = document.getElementById("pricetable");

	if(deleteRowIndex != -1){
		priceTable.deleteRow(deleteRowIndex);
		deleteRowIndex = -1;
	}else{
		parent.showHideFun();
		parent.changeShowMessage("请选择一行数据,选中的行背景为蓝色!",'yes','ok');
	}
}

//判断界面数据是否能提交
function isEditAndSubmit(){

	
	if(document.getElementById("cstate").value == 8){
		return true;
	}

	return false;
}

function setTdMsg(td,innerhtml){

	td.align="center";
	td.innerHTML = innerhtml;
}


//导入价格信息
function importPrice(){
	var msg = window.showModalDialog("uploadfilemiddle.jsp?constratpk="+document.getElementById("constratpk").value+"&random"+Math.random(),null,
			"dialogHeight:500px;dialogWidth:500px;");
	toUrlRed();
}


function toUrlRed(){
	parent.window.location.href="/portal/collaborative/main.jsp?url=/portal/self/constrat.do@type=2-constratpk="+document.getElementById("constratpk").value;
}



function onshowDivUnit(obj){
	 var msg = window.showModalDialog("produnit.jsp?random"+Math.random(),null,
			 "dialogHeight:240px;dialogWidth:310px;");

	 if(msg != null){
		var msgs = msg.split(";");

		if(obj != null){


			
			var children = obj.parentNode.childNodes;

			for(var index=0; index<children.length; index++){

				var name = children[index].name;

				if(name == "tprod_unit"){

					children[index].value = msgs[1];
					
				}else if(name == "newprodunit"){

					children[index].value = msgs[0];
					
				}
			}
		}
	 }
}


function dealReload(){

}
</script>
</div>
</body>
</html>
